package com.bailong.administrator.ausedcar.ui.search;

import android.os.Handler;

import com.bailong.administrator.ausedcar.bean.BuyCarsBean;
import com.bailong.administrator.ausedcar.config.UrlConfig;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/9/6.
 */
public class SearchPresreter implements SearchContract.Presreter{
    private SearchContract.Mode mode;
    private SearchContract.View view;
    private String serieid;
    public SearchPresreter(SearchContract.View view,String serieid){
        this.view = view;
        this.mode = new SearchMode();
        this.serieid=serieid;
    }

    @Override
    public void loadBuyCarsBean() {
        HashMap<String ,String> hashMap =new HashMap<>();
        hashMap.put(UrlConfig.parmas._apikey,"714497");
        hashMap.put(UrlConfig.parmas.appver,UrlConfig.BuyCarsValues.appver);
        hashMap.put(UrlConfig.parmas.brandid,UrlConfig.BuyCarsValues.brandid);
        hashMap.put(UrlConfig.parmas.channel,UrlConfig.BuyCarsValues.channel);
        hashMap.put(UrlConfig.parmas.cityid,UrlConfig.BuyCarsValues.cityid);
        hashMap.put(UrlConfig.parmas.limit,UrlConfig.BuyCarsValues.limit);
        hashMap.put(UrlConfig.parmas.nb,UrlConfig.BuyCarsValues.nb);
        hashMap.put(UrlConfig.parmas.offset,UrlConfig.BuyCarsValues.offset);
        hashMap.put(UrlConfig.parmas.os,UrlConfig.BuyCarsValues.os);
        hashMap.put(UrlConfig.parmas.search_cityid,UrlConfig.BuyCarsValues.search_cityid);
        hashMap.put(UrlConfig.parmas.serieid,serieid);

        mode.loadBuyCarsBean(new Callback<BuyCarsBean>() {
            @Override
            public void onResponse(Call<BuyCarsBean> call, Response<BuyCarsBean> response) {
                if (response.isSuccessful()){
                    final BuyCarsBean body = response.body();
                    Handler handler = new Handler();
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            view.onResponse(body);
                        }
                    });
                }
            }

            @Override
            public void onFailure(Call<BuyCarsBean> call, Throwable t) {

            }
        } , hashMap);
    }
}
